package com.advertising.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.advertising.model.ReleaseAddr;
import com.tgyt.common.tools.page.Pagination;
import com.tgyt.framework.dao.hibernate.Finder;
import com.tgyt.framework.dao.hspring.BaseDAO;
import com.tgyt.framework.dao.hspring.handler.IHandler;

@Repository(value = "releaseAddrDAO")
public class ReleaseAddrDAO extends BaseDAO<ReleaseAddr> {

	/**
	 * @Title: getPageList
	 * @Description: 具体某页显示多少条记录
	 * @param @param user 一条具体的用户信息
	 * @param @param page 当前页
	 * @param @param rows 一页显示多少条记录
	 * @param @return
	 * @return Pagination
	 * @throws
	 */
	public Pagination getPageList(ReleaseAddr release, int page, int rows,
			String sort, String order) {
		StringBuffer sb = new StringBuffer("from ReleaseAddr where 1=1");

		if (null != release) {
		
		/*	 if(release.getUser()!=null && !"".equals(release.getUser())){
				 sb.append(" and user.id="+release.getUser());
				}*/
			 
		}
		//sb.append(" order by  desc");

		if (sort != null && !"".equals(sort)) {
			sb.append(" order by " + sort);
			if (order != null && !"".equals(order)) {
				sb.append(" " + order);
			} else {
				sb.append(" desc");
			}
		}

		return super.getHandler().getPageList(Finder.create(sb.toString()),
				page, rows);
	}

	/**
	 * @Title: getMaxOrder
	 * @Description:获取操作信息表中的排序最大值
	 * @param @return
	 * @return int
	 * @throws
	 */
	public int getMaxOrder() {
		IHandler handler = this.getHandler();
		Object result = handler.findObj("select max(orderid) from Release ");
		if (result != null) {
			return (Integer) result;
		} else {
			return 0;
		}

	}

	/**
	 * @Title: getAll
	 * @Description: 获得所有记录
	 * @param @return
	 * @return List<Actions>
	 * @throws
	 */
	public List<ReleaseAddr> getAll() {
		return this.findList("from Release");

	}
}
